home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / rwvector.lha / RWVector2.1 / src / xgematop.cc < prev    next >
C/C++ Source or Header  |  1989-08-18  |  4KB  |  203 lines

  1. /*
  2.  *    Operator definitions for <A>GEMatrix
  3.  *
  4.  *    Copyright (C) 1988, 1989.
  5.  *
  6.  *    Dr. Thomas Keffer
  7.  *    Rogue Wave Associates
  8.  *    P.O. Box 85341
  9.  *    Seattle WA 98145-1341
  10.  *
  11.  *    Permission to use, copy, modify, and distribute this
  12.  *    software and its documentation for any purpose and
  13.  *    without fee is hereby granted, provided that the
  14.  *    above copyright notice appear in all copies and that
  15.  *    both that copyright notice and this permission notice
  16.  *    appear in supporting documentation.
  17.  *    
  18.  *    This software is provided "as is" without any
  19.  *    expressed or implied warranty.
  20.  *
  21.  *
  22.  *    @(#)xgematop.cc    2.1    8/18/89
  23.  */
  24.  
  25. #define NO_VECTOR_MATHFUN
  26. #include "rw/<A>GEMatrix.h"
  27. #define TYPE <T>_TYPE
  28. #include "vecdefs.h"
  29.  
  30. // g++ bug requires this:
  31. #if defined(__GNUG__) && TYPE==Float_TYPE
  32. #include "rw/DoubleVec.h"
  33. #endif
  34.  
  35. /******** Arithmetic assignment operators **********/
  36.  
  37. <A>GEMatrix&
  38. <A>GEMatrix::operator+=(const <A>GEMatrix& m)
  39. {
  40.   assertRowCol(m);
  41.   <T>Vec::operator+=(m);
  42.   return *this;
  43. }
  44.  
  45. <A>GEMatrix&
  46. <A>GEMatrix::operator+=(<T> s)
  47. {
  48.   <T>Vec::operator+=(s);
  49.   return *this;
  50. }
  51. <A>GEMatrix&
  52. <A>GEMatrix::operator-=(const <A>GEMatrix& m)
  53. {
  54.   assertRowCol(m);
  55.   <T>Vec::operator-=(m);
  56.   return *this;
  57. }
  58.  
  59. <A>GEMatrix&
  60. <A>GEMatrix::operator-=(<T> s)
  61. {
  62.   <T>Vec::operator-=(s);
  63.   return *this;
  64. }
  65. <A>GEMatrix&
  66. <A>GEMatrix::operator*=(const <A>GEMatrix& m)
  67. {
  68.   assertRowCol(m);
  69.   <T>Vec::operator*=(m);
  70.   return *this;
  71. }
  72.  
  73. <A>GEMatrix&
  74. <A>GEMatrix::operator*=(<T> s)
  75. {
  76.   <T>Vec::operator*=(s);
  77.   return *this;
  78. }
  79.  
  80. #if HAS_DIVIDE
  81. <A>GEMatrix&
  82. <A>GEMatrix::operator/=(const <A>GEMatrix& m)
  83. {
  84.   assertRowCol(m);
  85.   <T>Vec::operator/=(m);
  86.   return *this;
  87. }
  88.  
  89. <A>GEMatrix&
  90. <A>GEMatrix::operator/=(<T> s)
  91. {
  92.   <T>Vec::operator/=(s);
  93.   return *this;
  94. }
  95. #endif
  96.  
  97. /******** Increment / Decrement operators **********/
  98.  
  99. #if HAS_INCRDECR
  100. <A>GEMatrix&
  101. <A>GEMatrix::operator++()
  102. {
  103.   <T>Vec::operator++();
  104.   return *this;
  105. }
  106.  
  107. <A>GEMatrix&
  108. <A>GEMatrix::operator--()
  109. {
  110.   <T>Vec::operator--();
  111.   return *this;
  112. }
  113. #endif
  114.  
  115. /******** Arithmetic operators *****************/
  116.  
  117. // This macro recasts m, which is a <A>GEMatrix, as a <T>Vec:
  118. #define BASE(m) (*((<T>Vec*)&(m)))
  119.  
  120. // Unary minus
  121. <A>GEMatrix
  122. operator-(const <A>GEMatrix& m)
  123. {
  124.   return <A>GEMatrix(-BASE(m), m.rows(), m.cols());
  125. }
  126.  
  127. <A>GEMatrix
  128. operator*(const <A>GEMatrix& m1, const <A>GEMatrix& m2)
  129. {
  130.   m1.assertRowCol(m2);
  131.   return <A>GEMatrix( BASE(m1) * BASE(m2), m1.rows(), m1.cols());
  132. }
  133.  
  134. #if HAS_DIVIDE
  135. <A>GEMatrix
  136. operator/(const <A>GEMatrix& m1, const <A>GEMatrix& m2)
  137. {
  138.   m1.assertRowCol(m2);
  139.   return <A>GEMatrix( BASE(m1) / BASE(m2), m1.rows(), m1.cols());
  140. }
  141. #endif
  142.  
  143. <A>GEMatrix
  144. operator+(const <A>GEMatrix& m1, const <A>GEMatrix& m2)
  145. {
  146.   m1.assertRowCol(m2);
  147.   return <A>GEMatrix( BASE(m1) + BASE(m2), m1.rows(), m1.cols());
  148. }
  149.  
  150. <A>GEMatrix
  151. operator-(const <A>GEMatrix& m1, const <A>GEMatrix& m2)
  152. {
  153.   m1.assertRowCol(m2);
  154.   return <A>GEMatrix( BASE(m1) - BASE(m2), m1.rows(), m1.cols());
  155. }
  156.  
  157. // g++ bug requires the generation of an
  158. // explicit temporary in what follows:
  159.  
  160. <A>GEMatrix
  161. operator*(const <A>GEMatrix& m, <T> s)
  162. {
  163.   <T>Vec temp = BASE(m) * s;
  164.   return <A>GEMatrix( temp, m.rows(), m.cols());
  165. }
  166.  
  167. #if HAS_DIVIDE
  168. <A>GEMatrix
  169. operator/(const <A>GEMatrix& m, <T> s)
  170. {
  171.   <T>Vec temp = BASE(m) / s;
  172.   return <A>GEMatrix( temp, m.rows(), m.cols());
  173. }
  174.  
  175. <A>GEMatrix
  176. operator/(<T> s, const <A>GEMatrix& m)
  177. {
  178.   <T>Vec temp = s / BASE(m);
  179.   return <A>GEMatrix( temp, m.rows(), m.cols());
  180. }
  181. #endif
  182.  
  183. <A>GEMatrix
  184. operator+(const <A>GEMatrix& m, <T> s)
  185. {
  186.   <T>Vec temp = BASE(m) + s;
  187.   return <A>GEMatrix( temp, m.rows(), m.cols());
  188. }
  189.  
  190. <A>GEMatrix
  191. operator-(const <A>GEMatrix& m, <T> s)
  192. {
  193.   <T>Vec temp = BASE(m) - s;
  194.   return <A>GEMatrix( temp, m.rows(), m.cols());
  195. }
  196.  
  197. <A>GEMatrix
  198. operator-(<T> s, const <A>GEMatrix& m)
  199. {
  200.   <T>Vec temp = s - BASE(m);
  201.   return <A>GEMatrix( temp, m.rows(), m.cols());
  202. }
  203.